/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package jse;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 *
 * @author WangShuai
 */
public class Regex {

    public static void main(String[] args) {
        //由a-zA-Z_0-9.-组成的字符串
        //中括号为 或 的关系
        // \\.代表圆点
        // +代表一次或多次
//        Pattern p1 = Pattern.compile("[\\w\\.-]+");
//        Matcher m1 = p1.matcher("ws");
//        System.out.println(m1.matches());

        //以.txt结尾的字符串
        //.*  任意0或N个字符
        Pattern p2 = Pattern.compile(".*\\.txt");
        Matcher m2 = p2.matcher("1.txt");
        System.out.println(m2.matches());

        //用小括号括起来的为一个group
        Pattern p3 = Pattern.compile("(\\d+,)(\\d+)");
        String s = "123,456-34,345-111,222";
        Matcher m3 = p3.matcher(s);
        while(m3.find()){
            System.out.println("m.group():"+m3.group());
            //打印所有
            System.out.println("m.group(1):"+m3.group(1));
            //打印数字的
            System.out.println("m.group(2):"+m3.group(2));
            //打印字母的
            System.out.println();
        }
        System.out.println("捕获个数:groupCount()="+m3.groupCount());

        //1或N个字符a
        Pattern p4 = Pattern.compile("^a+$");
        Matcher m4 = p4.matcher("aaa");  
        System.out.println(m4.matches());

        //URL匹配
        Pattern p5 = Pattern.compile("^/mblogs?/([^/]+)/?$");
        //True： “/mblog/10001/”  “/mblogs/10001/” “/mblogs/10001”
        Matcher m5 = p5.matcher("/mblog/10001/");  
        System.out.println(m5.matches());
        
        String ss = "121322312a dsfjkoi 333 433 ";
        System.out.println(ss.replaceAll("[\\s\\D]", ""));
         
        
    }
}
